package com.gitee.wsl.mathematics.vector.ext

import com.gitee.wsl.math.Math
import com.gitee.wsl.mathematics.complex.quaternion.Quat
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec3.Vector3
import com.gitee.wsl.mathematics.vector.vec4.Vector4


/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a: Vector2<T, *>, b: Vector2<T,*>) = a.run { create(min(a.x, b.x), min(a.y, b.y)) }
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a: Vector2<T,*>, b:Vector3<T,*>) = b.run { create(min(a.x, b.x), min(a.y, b.y), min(zero, b.z))}
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a: Vector3<T, *>, b: Vector2<T,*>) = a.run { create(min(a.x, b.x), min(a.y, b.y), min(zero, a.z)) }
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a:Vector3<T,*>, b:Vector3<T,*>) = a.run { create(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z))}
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a: Vector4<T, *>, b:Vector4<T,*>) = a.run { create(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, b.w))}
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a:Vector4<T,*>, b:Vector3<T,*>) = a.run { create(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, zero))}
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a:Vector4<T,*>, b: Vector2<T,*>) = a.run { create(min(a.x, b.x), min(a.y, b.y), min(a.z, zero), min(a.w, zero))}
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a:Vector3<T,*>, b:Vector4<T,*>) = b.run { create(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(zero, b.w))}
/** The vector with minimum components of vectors [a] and [b]. */
fun <T:Number> Math.minComponents(a: Vector2<T,*>, b:Vector4<T,*>) = b.run { create(min(a.x, b.x), min(a.y, b.y), min(zero, b.z), min(zero, b.w))}
/** The quaternion with minimum components of quaternions [a] and [b]. */
fun  Math.minComponents(a: Quat, b: Quat) = a.run { create( min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, b.w))}

fun <T:Number> Math.minComponents(p1: Vector2<T, *>, vararg p2: Vector2<T, *>) = p1.run { create(
    min(p1.x, p2.minBy { it.x.toDouble() }.x),
    min(p1.y, p2.minBy { it.y.toDouble() }.y)
  )
} as Vector2<T, *>

